<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>Person Information</title>
<link href="${pageContext.request.contextPath }/css/bootstrap.min.css"
	rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/css/index.css"
	rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/font-awesome.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/menu-style.css">
</head>

<body>
	<div class="contain">
		<c:import url="header.jsp"></c:import>
		<c:import url="menu.jsp"></c:import>
		<div class="container-fluid">
			<div class="container">
				<h2>Person Information</h2>
				<hr>
				<div class="row person-info">

					<form class="form-horizontal info-get">
						<div class="form-group ">
							<label class="col-sm-2 control-label">Name:</label>
							<div class="col-sm-10">
								<p class="info-text">${client.cname }</p>
							</div>
							<label class="col-sm-2 control-label">Tel:</label>
							<div class="col-sm-10">
								<p class="info-text">${client.ctel }</p>
							</div>
							<label class="col-sm-2 control-label">Address:</label>
							<div class="col-sm-10">
								<p class="info-text">${client.caddress }</p>
							</div>
						</div>
					</form>
					<form class="form-horizontal info-update">
						<div class="form-group ">
							<label class="col-sm-2 control-label">Name:</label>
							<div class="col-sm-10">
								<input class='form-control cname' type='text'
									value="${client.cname }">
							</div>
							<label class="col-sm-2 control-label">Tel:</label>
							<div class="col-sm-10">
								<input class='form-control ctel' type='text'
									value="${client.ctel }">
							</div>
							<label class="col-sm-2 control-label">Address:</label>
							<div class="col-sm-10">
								<input class='form-control caddress' type='text'
									value="${client.caddress }">
							</div>
						</div>
					</form>
					<p class="all-btn">
						<button type="button" class="btn btn-default update-btn">Update</button>
					</p>
				</div>
				<h3>Complain Information</h3>
                <div>
                   <table class="table complain-table">
                       <tr style="background-color: #D64B2A;color: white;">
                           <th>order Time</th>
                           <th>Merchant</th>
                           <th>Complain Content</th>
                           <th>Complain Result</th>
                       </tr>
                   </table>
			</div>
			<!--container end-->
		</div>

	</div>
	<!--contain end-->

	<div class="footer"></div>
	<!--footer end-->
</body>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
<script src='${pageContext.request.contextPath }/js/TweenMax.min.js'></script>
<script src="${pageContext.request.contextPath }/js/menu-script.js"></script>
<script type="text/javascript">
    $(".update-btn").click(function(){
          str = $(this).text()=="Update"?"Submit":"Update";
          $(this).text(str);
          if($(this).text()=="Submit"){
              
              $(".info-get").css("display","none");
              $(".info-update").css("display","block");
              $("<button type='button' class='btn btn-default return-btn' onclick='returnClick()'>Return</button>").prependTo(".all-btn");
          }else{
        	  var cname = $(".cname").val();
        	  var ctel = $(".ctel").val();
        	  var caddress = $(".caddress").val();
        	  $.ajax({
     	    		type:"POST",//请求方式
     	    		url:"client/update",//请求路径
     	    		dataType:"json",
     	    		data:{"cname":cname,
     	    			  "ctel":ctel,
     	    			  "caddress":caddress,},//传参
     	    		success:function(msg){
     	    			location.href = "personInfo.jsp";    	    	    	
     	    		},
     	    		error:function(){
     	    			alert("修改失败");
     	    		}
     	    	})
          }
        
    })
    function returnClick(){
        $(".info-get").css("display","block");
        $(".info-update").css("display","none");
        $(".update-btn").text("Update");
        $(".return-btn").remove();
        
    }
    window.onload = function(){
    	 $.ajax({
	    		type:"POST",//请求方式
	    		url:"client/getComplain",//请求路径
	    		success:function(msg){
	    			for(var i=0;i<msg.length;i++){
	    				var compainResult;
	    				switch(msg[i].compainResult){
	    				case 0: compainResult = "未处理";
	    				break;
	    				case 1: compainResult = "投诉被驳回";
	    				break;
	    				case 2: compainResult = "商家已被扣除押金";
	    				break;
	    				case 3: compainResult = "该商家已被拉黑";
	    				break;
	    				}
	    			var complaintr = "<tr><td>"+msg[i].dt+"</td><td>"+msg[i].merchant.mName+"</td><td>"+msg[i].complain+"</td><td>"+compainResult+"</td></tr>"
	    			$(".complain-table").append(complaintr);
	    			}
	    			console.log(msg);
	    			 	    	    	
	    		},
	    		error:function(){
	    			console.log("获得商家投诉列表失败。");
	    		}
	    	})
    }
</script>
</html>